package com.lhy.admin.common.secure.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author hyluan
 * @ClassName: HandlerMethodInterceptor
 * @Description:  处理方法（非静态资源）拦截器
 * @date 2018/4/10 9:26
 * @Copyright: Copyright (c) 2018 wisedu
 */
@Slf4j
public abstract class HandlerMethodInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String request_info = request.getMethod() + " " + request.getRequestURI();
        log.info(request_info);
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            handleMethod(request, handlerMethod);
        }
        return true;
    }

    protected abstract void handleMethod(HttpServletRequest request, HandlerMethod handlerMethod);

}
